/*********************************************************************************
 *      Copyright:  (C) 2021 litupei<lismilepei@163.com>
 *                  All rights reserved.
 *
 *       Filename:  prj_mosquitto_thread.h
 *    Description:  This file is prj_mosquitto_thread.h
 *                 
 *        Version:  1.0.0(2021年08月10日)
 *         Author:  litupei <lismilepei@163.com>
 *      ChangeLog:  1, Release initial version on "2021年08月10日 17时23分47秒"
 *                 
 ********************************************************************************/

#ifndef _PRJ_MOSQUITTO_THREAD_H_
#define _PRJ_MOSQUITTO_THREAD_H_

#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <unistd.h>
#include <stdlib.h>
#include <pthread.h>
#include <ctype.h>
#include <signal.h>

#include "mosquitto.h"
#include "zlog.h"
#include "sqlite3.h"

#include "prj_zlog.h"
#include "prj_iniparser.h"
#include "prj_cjson.h"
#include "prj_sqlite.h"

typedef void *(THREAD_BODY) (void *thread_arg);

#if 1
//初始化线程
int thread_init(pthread_attr_t 	*thread_attr);
#endif

#if 1
int thread_start(pthread_t *tid, THREAD_BODY *thread_workfunc, void *thread_arg);
#endif

//发布连接函数
void *pub_connect(void *args);

//发布连接回调函数，确认是否连接成功
void pub_connect_callback(struct mosquitto *mosq, void *obj, int rv);

//订阅连接函数
void *sub_connect(void *args);

//订阅连接回调函数，确认是否连接成功
void sub_connect_callback(struct mosquitto *mosq, void *obj, int rv);

//订阅失败回调函数
void sub_disconnect_callback(struct mosquitto *mosq, void *obj, int rv);

//订阅回调函数
void sub_subscribe_callback(struct mosquitto *mosq, void *obj, int mid, int qos_count, const int *granted_qos);

//发布失败回调函数
void pub_on_disconnect(struct mosquitto *mosq, void *obj, int rc);

//发布回调函数
void pub_on_publish(struct mosquitto *mosq, void *obj, int mid);

//订阅消息回调函数
void sub_message(struct mosquitto *mosq, void *obj, const struct mosquitto_message *message);
#endif

